
from twisted.internet import reactor, protocol
from twisted.protocols import basic
from sys import stdout

class QuickDisconnectProtocol(basic.LineReceiver):
    def connectionMade(self):
        print "**Connected to %s" % self.transport.getPeer()
        #self.transport.loseConnection()

    def lineReceived(self, line):
        print "deataReceived !"
        stdout.write(line)
        self.transport.loseConnection()

#class BasicClientFactory(protocol.ClientFactory):
#    protocol = QuickDisconnectProtocol

#    def startedConnecting(self,connector):
#        print("Start to connect")

#    def clientConnectionLost(self, connector, reason):
#        print "==Lost connection: %s" % reason.getErrorMessage()
#        ReconnectingClientFactory.clientConnectionLost(self,connector,reason)
#        reactor.stop()

#    def clientConnectionFailed(self, connector, reason):
#        print "--Connection failed: %s" % reason.getErrorMessage()
#        ReconnectingClientFactory.clientConnectionFailed(self,connector,reason)
#        reactor.stop()

if __name__ == '__main__':
#    reactor.connectTCP('www.google.com', 80, BasicClientFactory())
    clientFactory = protocol.ClientFactory()
    clientFactory.protocol = QuickDisconnectProtocol
    reactor.connectTCP('www.google.com', 80, clientFactory)
    reactor.run()
